package operation;

import book.Book;
import book.BookList;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/10/29
 * Time: 11:49
 * Description:
 */
public class AddOperation implements IOPeration{

    public void work(BookList bookList) {
        System.out.println("新增书籍");
        System.out.println("请输入图书的名字:");
        String name = scanner.nextLine();
        System.out.println("请输入图书的作者:");
        String author = scanner.nextLine();
        System.out.println("请输入图书的类型:");
        String type = scanner.nextLine();
        System.out.println("请输入图书的价格:");
        int price = scanner.nextInt();
        Book book = new Book(name,author,price,type);

        int size = bookList.getUsedSize();
        for (int i = 0; i < size; i++) {
            Book bookCurrent = bookList.getBook(i);
            if(bookCurrent.getName().equals(name)) {
                System.out.println("书架有这本书");
                return;
            }
        }

        bookList.setBooks(size,book);
        bookList.setUsedSize(size+1);
        System.out.println("新增成功！");
    }
}
